﻿var dt = new Date();

function SignWin(fNo, isView, hasSign) {
    if (fNo.indexOf("Form_Exam") >= 0) { window.open('ExamWelcome.aspx?id=' + fNo.substr(10));return;}
    var DataPannel;
    switch (fNo.substr(0, 9)) {
        case "Form_Week":
            DataPannel = new Ext.Panel({ region: 'center', autoScroll: true, html: '<iframe src="WeekInfo.aspx?formNo=' + fNo + '" frameborder="0" width=100% height=100%></iframe>' }); break;
        case "Form_Vehi":
            DataPannel = new Ext.Panel({ region: 'center', autoScroll: true, html: '<iframe src="VehiInfo.aspx?formNo=' + fNo + '" frameborder="0" width=100% height=100%></iframe>' }); break;
        case "Form_Evec":
            DataPannel = new Ext.Panel({ region: 'center', autoScroll: true, html: '<iframe src="EvecInfo.aspx?formNo=' + fNo + '" frameborder="0" width=100% height=100%></iframe>' }); break;
        case "Form_Over":
            DataPannel = new Ext.Panel({ region: 'center', autoScroll: true, html: '<iframe src="OvertimeInfo.aspx?formNo=' + fNo + '" frameborder="0" width=100% height=100%></iframe>' }); break;
        case "Form_Vaca":
            DataPannel = new Ext.Panel({ region: 'center', autoScroll: true, html: '<iframe src="VacationInfo.aspx?formNo=' + fNo + '" frameborder="0" width=100% height=100%></iframe>' }); break;
        case "Form_Meet":
            DataPannel = new Ext.Panel({ region: 'center', autoScroll: true, html: '<iframe src="MeetingRoomInfo.aspx?formNo=' + fNo + '" frameborder="0" width=100% height=100%></iframe>' }); break;
        case "Form_Perc":
            DataPannel = new Ext.Panel({ region: 'center', autoScroll: true, html: '<iframe src="PerchaseInfo.aspx?formNo=' + fNo + '" frameborder="0" width=100% height=100%></iframe>' }); break;
        case "Form_Rece":
            DataPannel = new Ext.Panel({ region: 'center', autoScroll: true, html: '<iframe src="ReceptionInfo.aspx?formNo=' + fNo + '" frameborder="0" width=100% height=100%></iframe>' }); break;
        case "Form_Invi":
            DataPannel = new Ext.Panel({ region: 'center', autoScroll: true, html: '<iframe src="InviteInfo.aspx?formNo=' + fNo + '" frameborder="0" width=100% height=100%></iframe>' }); break;
        case "Form_Card":
            DataPannel = new Ext.Panel({ region: 'center',autoScroll: true, html: '<iframe src="CardSign.aspx?formNo=' + fNo + '" frameborder="0" width=100% height=100%></iframe>' }); break;
        default:
            Ext.ux.Toast.msg('提示', '未找到该表单,请联系技术员修复!'); break;
    }
    var win;
    if (hasSign) {
        //#region 签核模版
        var tpl0 = new Ext.XTemplate(
        '开始<br />▼',
            '<tpl for=".">',
            '<tpl if="IsCurrent==0 || CheckEmpId!=' + Cookies.get("empId") + '">',
            '<table cellspacing =0>',
            '<tr><td>意见</td><td colspan="3">{Comment}</td></tr>',
            '<tr><td width="25%">{CheckNode}</td><td width="25%">{Checker}</td><td width="25%">签核日期</td><td>{CheckDate:this.formatCheckDate()}</td></tr>',
            '</table>',
            '状态:{IsPass:this.formatSignResult()}<br />▼',
            '</tpl>',
            '<tpl if="IsCurrent==1 && CheckEmpId==' + Cookies.get("empId") + '">',
            '<table cellspacing =0>',
            '<tr><td>意见</td><td colspan="3" class="tdComment"><textarea id="txtComment" style="width:100%;" rows="2" class="x-form-field"></textarea></td></tr>',
            '<tr><td width="25%">{CheckNode}</td><td width="25%">{[unescape(Cookies.get("empName"))]}</td><td width="25%">签核日期</td><td>{[dt.format("Y-m-d")]}</td></tr>',
            '<tr><td colspan="4" class="tdSign"><input type="button" value="通过" onclick="sign({Id},\''+fNo+'\',this);" class="addicon"><input type="button" value="退件" onclick="sign({Id},\''+fNo+'\',this);" class="icon-delete"></td></tr>',
            '</table>▼',
            '</tpl>',
            '</tpl>',
            '<br />结束',
            {
                formatCheckDate: function (cd) {
                    if (cd == undefined || cd == null) {
                        return '';
                    } else {
                        var dt = eval("new " + cd.substr(1, cd.length - 2));
                        return dt.format('Y-m-d');
                    }
                }
            },
            {
                formatSignResult: function (isPass) {
                    if (isPass == null) {
                        return '待签';
                    } else if (isPass == 1) {
                        return '通过';
                    } else if (isPass == 0) {
                        return '退件';
                    }
                }
            }
        );
        //#endregion

        var SignPannel = new Ext.Panel(
        {
            title: '签核流程', region: 'west', split: false, width: 280, collapsible: false, autoScroll: true,
            html: '<div id="tpl-0"></div>'
        });

        win = new Ext.Window(
        {
            id: 'GeneralWin', title: '申请签核',closable: true,width:920,height:550,
            layout: 'border', items: [SignPannel, DataPannel]
        });

        //绑定签核流程
        Ext.Ajax.request({
            url: '/Sign.mvc/GetSignNodes',
            method: 'POST',
            success: function (response, options) {
                var record = Ext.util.JSON.decode(response.responseText);
                tpl0.append('tpl-0', record);
            },
            params: {
                formNo: fNo
            },
            failure: function (form, action) {
                if (action.failureType == 'server') {
                    obj = Ext.util.JSON.decode(action.response.responseText);
                    Ext.Msg.alert('错误:', obj.errors.reason);
                }
                if (action.failureType == 'client') {
                    Ext.ux.Toast.msg('提示', '数据不正确，请核对后重新操作');
                }
            }
        });
    } else {
        win = new Ext.Window(
        {
            id: 'GeneralWin', title: '表单内容',closable: true, width:700, height:450,
            layout: 'border', items:DataPannel
        });
    }
    win.show();

    if (isView) {
        try {
            Ext.getCmp('BtnSave').hide();
            Ext.getCmp('BtnSubmit').hide();
        } catch (ex) { }
    }
};

function RefreshList(fNo) {
    switch (fNo.substr(0, 9)) {
        case "Form_Week": if (Ext.getCmp("WeeklyMgr") != null) { Ext.getCmp("WeeklyMgr").getStore().reload(); } break;
        case "Form_Vehi": if (Ext.getCmp("VehicleMgr") != null) { Ext.getCmp("VehicleMgr").getStore().reload(); } break;
        case "Form_Evec": if (Ext.getCmp("EvectionMgr") != null) { Ext.getCmp("EvectionMgr").getStore().reload(); } break;
        case "Form_Over": if (Ext.getCmp("OvertimeMgr") != null) { Ext.getCmp("OvertimeMgr").getStore().reload(); } break;
        case "Form_Vaca": if (Ext.getCmp("VacationMgr") != null) { Ext.getCmp("VacationMgr").getStore().reload(); } break;
        case "Form_Meet": if (Ext.getCmp("MeetingRoomMgr") != null) { Ext.getCmp("MeetingRoomMgr").getStore().reload(); } break;
        case "Form_Perc": if (Ext.getCmp("PerchaseMgr") != null) { Ext.getCmp("PerchaseMgr").getStore().reload(); } break;
        case "Form_Rece": if (Ext.getCmp("ReceptionMgr") != null) { Ext.getCmp("ReceptionMgr").getStore().reload(); } break;
        case "Form_Invi": if (Ext.getCmp("InviteMgr") != null) { Ext.getCmp("InviteMgr").getStore().reload(); } break;
        default:
            Ext.ux.Toast.msg('提示', '数据列表刷新未成功,请联系技术员修复!'); break;
    }
}